'use strict';

const RequestJsonApi = require('../lib/class/requestJsonApi');

module.exports = app => {
  // 定义参数 继承request类

  const host = app.config.apiServiceLocation.product;
  const url = '/products';
  const dataType = 'products';

  const products = new Products({ host, url, dataType });

  return products;
};

class Products {
  constructor (options) {
    this.requestJsonApi = new RequestJsonApi(options);
  }

  async getMenuProducts (shopId) {
    // { idList: [1, 3, 5, 6, 7] }
    const data = await this.requestJsonApi.get({ filters: { userId: shopId, status: 2 }, pages: { size: 100 }, fields: { products: 'name,logo,minPrice,prices,productType' } });
    return data;
  }
  async getProductDetail (idList) {
    // const fields = { products: 'name,logo,prices,productType' };
    // const includes = ['slides', 'description', 'prices'];
    const data = await this.requestJsonApi.get({ idList });
    return data;
  }
}
